"use strict";

const Controller = require("egg").Controller;

class GirlsManage extends Controller {



    async addGirl() {
        const { ctx } = this;
        const params = {
            name: '小白',
            age: 18,
            skill: '头疗!!'
        };
        const res = await ctx.service.testdb.addGirl(params);
        ctx.body = `添加女孩+ ${Date()}❤️`;
        if (res) {
            ctx.body += 'add succeed';
        } else {
            ctx.body += 'add failed';
            ctx.body += `check if you have been created corresponding database and table in you mysql_database.`;
        }
    }

    // 删除数据库
    async delGirl() {
        const { ctx } = this;
        const id = { "id": 3 };
        const res = await ctx.service.testdb.delGirl(id);
        console.log(res);
        if (res) {
            ctx.body = '删除女孩-成功';
        } else {
            ctx.body = '删除失败';
        }

    }


    async updateGirl() {
        const { ctx } = this;
        const params = {
            // ensure the correct id:,if the database table without the id you specified,than you cant see the updating result.!!
            id: 2,
            name: '小白@',
            age: 20,
            skill: '头疗,oop'
        };
        const res = await ctx.service.testdb.updateGirl(params);
        console.log(res + "😎😎😎");
        if (res) {
            ctx.body = '修改女孩-成功👌';
        } else {
            ctx.body = '修改失败';
        }
    }

    async getGirls() {
        const { ctx } = this;

        const res = await ctx.service.testdb.getGirls();

        ctx.body = '查询女孩:' + JSON.stringify(res);
    }
    // async getGirls() {
    //     const { ctx } = this;

    //     ctx.body = "查询女孩";
    // }
}

module.exports = GirlsManage;